package com.didi.gulimall.member.service.impl;

import com.alibaba.fastjson.TypeReference;
import com.didi.gulimall.api.OrderApiService;
import com.didi.gulimall.common.exception.DuplicateFieldsException;
import com.didi.gulimall.common.to.OrderTo;
import com.didi.gulimall.common.utils.R;
import com.didi.gulimall.member.service.MemberOrderWebService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 10626
 * @Create 2021/6/8 14:40
 */
@Service
@Slf4j
public class MemberOrderWebServiceImpl implements MemberOrderWebService {

    @Autowired
    private OrderApiService orderApiService;

    @Override
    public List<OrderTo> memberOrderHtml() {
        R r = orderApiService.memberOrderList();
        if (r.getCode() != 0) {
            log.error("远程调用order错误:{}", r.getMsg());
            throw new DuplicateFieldsException(r.getMsg());
        }
        return r.getData(new TypeReference<List<OrderTo>>() {
        });
    }
}
